<template>
	<el-form ref="formRef" :model="formData" label-width="150px">
		<el-form-item label="微信支付：">
			<div>
				<el-radio-group v-model="formData.wechat_status">
					<el-radio :label="1">开启</el-radio>
					<el-radio :label="0">关闭</el-radio>
				</el-radio-group>
				<div class="el-form-tips">请选择微信支付开启或关闭，关闭时用户端不显示</div>
			</div>
		</el-form-item>
		<el-form-item label="支付宝支付：">
			<div>
				<el-radio-group v-model="formData.alipay_status">
					<el-radio :label="1">开启</el-radio>
					<el-radio :label="0">关闭</el-radio>
				</el-radio-group>
				<div class="el-form-tips">请选择支付宝支付开启或关闭，关闭时用户端不显示</div>
			</div>
		</el-form-item>
		<el-form-item label="余额支付：">
			<div>
				<el-radio-group v-model="formData.balance_status">
					<el-radio :label="1">开启</el-radio>
					<el-radio :label="0">关闭</el-radio>
				</el-radio-group>
				<div class="el-form-tips">请选择余额支付开启或关闭，关闭时用户端不显示</div>
			</div>
		</el-form-item>
		<el-form-item label="线下支付：">
			<div>
				<el-radio-group v-model="formData.cash_status">
					<el-radio :label="1">开启</el-radio>
					<el-radio :label="0">关闭</el-radio>
				</el-radio-group>
				<div class="el-form-tips">请选择线下支付开启或关闭，关闭时用户端不显示</div>
			</div>
		</el-form-item>
	</el-form>
	<footerSubmit>
		<el-button v-auth="'setting/pay/edit'" type="primary" @click="handleSubmit">保存</el-button>
	</footerSubmit>
</template>

<script lang="ts" setup name="payBaseEdit">
import { ref, reactive, onMounted } from 'vue';
import { payLists, payChange } from '/@/api/setting/pay';
import { messageSuccess } from '/@/utils/message';

const formRef = ref(null);

// 表单数据
const formData = reactive({
	wechat_status: '',
	alipay_status: '',
	balance_status: '',
	cash_status: '',
});

// 获取数据
const getData = async () => {
	const data = await payLists();

	for (const key in data) {
		if (data[key]?.identify && data[key].identify) {
			formData[data[key].identify + '_status'] = data[key].status;
		}
	}
};

// 保存提交
const handleSubmit = async () => {
	await payChange(formData);
	messageSuccess('设置成功');
	getData();
};

onMounted(() => {
	getData();
});
</script>
